package com.xihuanjun.util;

import java.awt.*;
import java.awt.event.InputEvent;

public class MouseUtils {
    static Robot robot;

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
    }

    public static void moveTo(int x,int y){
        robot.mouseMove(x,y);
    }

    public static  void clickLeftOne(){
        robot.mousePress(InputEvent.BUTTON1_MASK);//按下左键
        robot.mouseRelease(InputEvent.BUTTON1_MASK);//释放左键
    }

    /**
     * 移动鼠标并单机
     * @param x
     * @param y
     */
    public static void MoveLeft(int x,int y){
        moveTo(x,y);
        clickLeftOne();
    }
}
